package com.smalls.redshoes.util;

import android.content.Context;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.smalls.redshoes.R;

public class AnimationUtil {
    public static void setAnimation(RelativeLayout layout, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale);
        layout.bringToFront();
        animation.setRepeatCount(1);
        animation.setFillAfter(true);
        layout.startAnimation(animation);
    }

    public static void setRollAnimation(FrameLayout layout, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale_roll);
        layout.bringToFront();
        animation.setRepeatCount(1);
        animation.setFillAfter(true);
        layout.startAnimation(animation);
    }

    public static void setRollAnimation(RelativeLayout layout, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale_roll);
        layout.bringToFront();
        animation.setRepeatCount(1);
        animation.setFillAfter(true);
        layout.startAnimation(animation);
    }

    public static void narrowAnimation(FrameLayout layout, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.scaleback);
        animation.setRepeatCount(1);
        animation.setFillAfter(true);
        layout.startAnimation(animation);
    }

    public static void narrowAnimation(RelativeLayout layout, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.scaleback);
        animation.setRepeatCount(1);
        animation.setFillAfter(true);
        layout.startAnimation(animation);
    }

    public static void scale(View view, float numer) {
        ScaleAnimation animation = new ScaleAnimation(1.0f, numer, 1.0f, numer, 1, 0.5f, 1, 0.5f);
        animation.setDuration(200);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    }

    public static void scaleBack(View view, float number) {
        ScaleAnimation animation = new ScaleAnimation(number, 1.0f, number, 1.0f, 1, 0.5f, 1, 0.5f);
        animation.setDuration(200);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    }

    public void sranslateShow(View view) {
        Animation mShowListAnim = new TranslateAnimation(1, -1.0f, 1, 0.0f, 1, 0.0f, 1, 0.0f);
        mShowListAnim.setDuration(300);
        view.startAnimation(mShowListAnim);
    }

    public void sranslateHide(View view) {
        Animation mHideListAnim = new TranslateAnimation(1, 0.0f, 1, -1.0f, 1, 0.0f, 1, 0.0f);
        mHideListAnim.setDuration(300);
        view.startAnimation(mHideListAnim);
    }

    public void sranslateUp(View view) {
        Animation mHideListAnim = new TranslateAnimation(1, 0.0f, 1, 0.0f, 1, 0.0f, 1, -1.0f);
        mHideListAnim.setDuration(300);
        view.startAnimation(mHideListAnim);
    }

    public void sranslateDown(View view) {
        Animation mHideListAnim = new TranslateAnimation(1, 0.0f, 1, 0.0f, 1, -1.0f, 1, 0.0f);
        mHideListAnim.setDuration(300);
        view.startAnimation(mHideListAnim);
    }

    public static void sranslateLeft(View view, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.page_up_anime);
        animation.setRepeatCount(2);
        view.startAnimation(animation);
    }

    public static void sranslateRight(View view, Context context) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.page_anime);
        animation.setRepeatCount(2);
        view.startAnimation(animation);
    }

    public static void alphaDeepToShallow(View view) {
        AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f);
        animation.setDuration(300);
        view.startAnimation(animation);
    }
}
